<?php
$username = $_COOKIE['username'];
$dir = "./admin/main/Exam/Python/output/".$username."/";

if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if ($file != "." && $file != "..") {
                if (is_file($dir . '/' . $file)) {
                    $extension = pathinfo($file, PATHINFO_EXTENSION);
                    if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) {
                        echo '<img src="' . $dir . '/' . $file . '" />';
                    }
                }
            }
        }
        closedir($dh);
    }
}
?>